import { fromJS } from 'immutable'
import * as constants from './constants'

const defaultState = fromJS({
  topicList: [],
  articleList: [],
  recommendList: [],
  writerList: [
    {
      id: 1,
      author: '斯石英',
      desc: '写了2842.5k字 · 5.8k喜欢',
      pic: 'https://upload.jianshu.io/users/upload_avatars/22523644/0084ffd4-2f56-48db-82ba-e7b2f70b0595.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/96/h/96/format/webp',
      isFollow: false
    }
  ],
  page: 1,
  downloadHover: false,
  showScroll: true
})
// eslint-disable-next-line import/no-anonymous-default-export
export default (state = defaultState, action) => {
  switch (action.type) {
    case constants.MOUSE_ENTER:
      return state.set('downloadHover', true)
    case constants.MOUSE_LEAVE:
      return state.set('downloadHover', false)
    case constants.HOME_DATA:
      return state.merge({
        topicList: fromJS(action.topicList),
        articleList: fromJS(action.articleList),
        recommendList: fromJS(action.recommendList)
      })
    case constants.ADD_ARTICLE_LIST:
      return state.merge({
        articleList: state.get('articleList').concat(action.list),
        page: action.nextPage
      })
    case constants.TOGGLE_SCROLL_TOP:
      return state.set('showScroll', action.show);
    default:
      return state
  }
}